/**
 * 绘制圆形区域（平面）
 */
export function drawCircleArea(viewer, lon, lat, radius, color, alpha = 0.5) {
  // 添加实体并返回它
  const entity = viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(lon, lat),
    ellipse: {
      semiMajorAxis: radius,  // 半径
      semiMinorAxis: radius,  // 半径
      material: Cesium.Color[color.toUpperCase()].withAlpha(alpha),  // 填充颜色
      outline: true,  // 显示轮廓
      outlineColor: Cesium.Color[color.toUpperCase()],  // 轮廓颜色
      outlineWidth: 2  // 轮廓线宽度
    }
  });

  // 返回创建的实体对象
  return entity;
}

/**
 * 绘制平行四边形区域（平面）
 */
export function drawParallelogramArea(viewer, positions, color, alpha = 0.5) {
  viewer.entities.add({
    polygon: {
      hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
      material: Cesium.Color[color.toUpperCase()].withAlpha(alpha),
      outline: true,
      outlineColor: Cesium.Color[color.toUpperCase()],
      outlineWidth: 2
    }
  });
}



/**
 * 绘制正方形区域（平面）
 */
export function drawSquareArea(viewer, lon, lat, sideLength, color, alpha = 0.5) {
  const halfSide = sideLength / 2;
  const nw = Cesium.Cartesian3.fromDegrees(lon - halfSide / 111320, lat + halfSide / 110574);
  const ne = Cesium.Cartesian3.fromDegrees(lon + halfSide / 111320, lat + halfSide / 110574);
  const se = Cesium.Cartesian3.fromDegrees(lon + halfSide / 111320, lat - halfSide / 110574);
  const sw = Cesium.Cartesian3.fromDegrees(lon - halfSide / 111320, lat - halfSide / 110574);

  viewer.entities.add({
    polygon: {
      hierarchy: new Cesium.PolygonHierarchy([nw, ne, se, sw]),
      material: Cesium.Color[color.toUpperCase()].withAlpha(alpha),
      outline: true,
      outlineColor: Cesium.Color[color.toUpperCase()],
      outlineWidth: 2
    }
  });
}
